package ui.util;

import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ui.views.ScenarioView;
import ui.views.property.MarketVariableProp;
import ui.views.property.ScenarioProp;
import dao.EgnMarketVari;
import dao.EgnPortfolio;
import dao.EgnRstScenarioId;

public class EntityAdaptorFactory implements IAdapterFactory{
	private final static Logger logger = LoggerFactory.getLogger(EntityAdaptorFactory.class);

	public Object getAdapter(Object adaptableObject, Class adapterType) {
//		logger.debug("Start Adapter Factory{}", adaptableObject.toString());
		if (adapterType == IPropertySource.class){
//			logger.debug("IN Adapter Factory");
			if(adaptableObject instanceof EgnRstScenarioId){
				return new ScenarioProp((EgnRstScenarioId)adaptableObject);
			}
			else if (adaptableObject instanceof EgnMarketVari){
				return new MarketVariableProp((EgnMarketVari)adaptableObject);
			}
			else if (adaptableObject instanceof EgnPortfolio || adaptableObject instanceof String){
//				return new PortfolioProp((EgnPortfolio)adaptableObject);
			}
		}
		 if((adapterType == IPropertySheetPage.class)){
//			logger.debug("IN Adapter Factory1");
			if(adaptableObject instanceof ScenarioView){
				return new TabbedPropertySheetPage((ScenarioView)adaptableObject);
			}
		}
		return null;
	}

	public Class[] getAdapterList() {
		return new Class[] {IPropertySource.class};
	}

}
